<?php
require_once(ML_ROOT."/service.php");

function on_index()
{
	require_once(ML_DATA."/model.php");
	
	/*
	if ($_SERVER["REQUEST_METHOD"] == "POST") {
		$selections = $_POST[Protocol::SELECTIONS];
		DBConnector::connect();
		Model::delete($selections);
		DBConnector::close();
		header("Location: ".url("/admin/models.php"));
	}
	*/
	
	set_navigation("models");
	
	DBConnector::connect();
	$model_list = Model::get_list();
	DBConnector::close();
	
	set_view_data(Protocol::MODEL_LIST, $model_list);
}

function on_detail()
{
	require_once(ML_DATA."/model.php");
	require_once(ML_DATA."/photo.php");
	
	/*
	if ($_SERVER["REQUEST_METHOD"] == "POST") {
		$selections = $_POST[Protocol::SELECTIONS];
		DBConnector::connect();
		Model::delete($selections);
		DBConnector::close();
		header("Location: ".url("/admin/models.php"));
	}
	*/
	
	set_navigation("models");
	
	DBConnector::connect();
	$model = Model::get($_GET[Protocol::ID]);
	$photo_list = Photo::get_list_by_model_id($_GET[Protocol::ID]);
	DBConnector::close();
	
	set_view_data(Protocol::MODEL, $model);
	set_view_data(Protocol::PHOTO_LIST, $photo_list);
}